use core::{Package, VirtualManifest, EitherManifest, SourceId};
use core::{PackageIdSpec, Dependency};
use ops;
-use util::{Config, CargoResult, Filesystem};
+use util::{Config, CargoResult, Filesystem, human};
use util::paths;
/// The core abstraction in Cargo for working with a workspace of crates.
/// actually a "virtual Cargo.toml", in which case an error is returned
/// indicating that something else should be passed.
pub fn current(&self) -> CargoResult<&Package> {
+ self.current_opt().ok_or_else(||
+ human(format!("manifest path `{}` is a virtual manifest, but this \
+ command requires running against an actual package in \
+ this workspace", self.current_manifest.display()))
+ )
+ }
+
+ pub fn current_opt(&self) -> Option<&Package> {
match *self.packages.get(&self.current_manifest) {
- MaybePackage::Package(ref p) => Ok(p),
- MaybePackage::Virtual(..) => {
- bail!("manifest path `{}` is a virtual manifest, but this \
- command requires running against an actual package in \
- this workspace", self.current_manifest.display())
- }
+ MaybePackage::Package(ref p) => Some(p),
+ MaybePackage::Virtual(..) => None
}
}
let resolve = try!(resolve_with_previous(registry, ws,
Method::Everything,
prev.as_ref(), None));
- if try!(ws.current()).package_id().source_id().is_path() {
+
+ // Avoid writing a lockfile if we are `cargo install`ing a non local package.
+ if ws.current_opt().map(|pkg| pkg.package_id().source_id().is_path()).unwrap_or(true) {
try!(ops::write_pkg_lockfile(ws, &resolve));
}
Ok(resolve)
.file("src/main.rs", "fn main() {}");
p.build();
- assert_that(cargo_process("install").arg("--git").arg(p.url().to_string()),
+ // use `--locked` to test that we don't even try to write a lockfile
+ assert_that(cargo_process("install").arg("--locked").arg("--git").arg(p.url().to_string()),
execs().with_status(0).with_stderr(&format!("\
[UPDATING] git repository `[..]`
[COMPILING] foo v0.1.0 ([..])